<?php
namespace app\common\controller;

/**
 * 巡店类
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/10/15
 * Time: 11:46
 */
class Patrol{

    /**
     * 获取巡店工位信息
     * @param $regionid
     * @param $wsid
     * @return array
     */
    public function get_patrol_ws_info($regionid,$wsid){
        $data = [];

        //$maps = [];
        //$maps[] = ['cp_type','=',$cp_type];
        //$maps[] = ['cp_branchid','=',$cp_branchid];
        //$maps[] = ['branchid','=',$branchid];
        //$maps[] = ['floorid','=',$floorid];
        //$maps[] = ['regionid','=',$regionid];
        //$maps[] = ['wsid','=',$wsid];
        //$maps[] = ['status','=',1];
        //$crs_detail = model('cp_region_ws')->get_detail($maps,'id,use_status,use_rate,person_num,is_holiday_work,is_evening_work,ccids,remark,status','id desc');
        //if(!empty($crs_detail)){
            //$data['use_status'] = $crs_detail['use_status'];
            //$data['use_status_zw'] = $crs_detail->use_status_name;
            //$data['use_rate'] = $crs_detail['use_rate'];
            //$data['person_num'] = $crs_detail['person_num'];
            //$data['is_holiday_work'] = $crs_detail['is_holiday_work'];
            //$data['is_evening_work'] = $crs_detail['is_evening_work'];
            //$data['ccids'] = json_decode($crs_detail['ccids'],true);
            //$data['remark'] = $crs_detail['remark'];
            //$data['status'] = $crs_detail['status'];
            //$data['status_zw'] = $crs_detail->status_name;
        //}else{
            //$data['use_status'] = -1;
            //$data['use_status_zw'] = '';
            //$data['use_rate'] = 0;
            //$data['person_num'] = 1;
            //$data['is_holiday_work'] = 0;
            //$data['is_evening_work'] = 0;
            //$data['ccids'] = [];
            //$data['remark'] = '';
            //$data['status'] = 0;
            //$data['status_zw'] = '未完成';
        //}
        $data['use_status'] = 2;
        $data['use_status_zw'] = '无人';
        $data['use_rate'] = 0;
        $data['person_num'] = 1;
        $data['is_holiday_work'] = 0;
        $data['is_evening_work'] = 0;
        $data['ccids'] = [];
        $data['remark'] = '';
        $data['status'] = 1;
        $data['status_zw'] = '已完成';
        return $data;
    }

    /**
     * 计算巡店工位使用率
     * @param $cp_type
     * @param $wsid
     * @return mixed
     */
    public function count_patrol_ws_use_rate($cp_type,$wsid){
        $maps = [];
        $maps[] = ['cp_type','=',$cp_type];
        $maps[] = ['wsid','=',$wsid];
        $total_num = model('cp_region_ws')->get_count($maps,'id');

        $maps = [];
        $maps[] = ['cp_type','=',$cp_type];
        $maps[] = ['wsid','=',$wsid];
        $maps[] = ['use_status','=',1];
        $use_num = model('cp_region_ws')->get_count($maps,'id');

        $use_rate = ($total_num > 0) ? $use_num / $total_num : 0;
        $use_rate = $use_rate * 100;
        $data['use_rate'] = round($use_rate,0);
        return $data;
    }
}